package zj.com.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import org.xutils.DbManager;

import java.util.List;

import zj.com.activities.JcxDetailActivity;
import zj.com.adapter.JcxAdapter;
import zj.com.app.ZjApplication;
import zj.com.db.DBUtil;
import zj.com.model.Dic;
import zj.com.model.DzgDetail;
import zj.com.model.DzgDetailDB;
import zj.com.model.InspectItem;
import zj.com.util.Constants;
import zj.com.zj.R;

/**

 */
public class DzgDetailFragment extends Fragment{


    public TextView xz_tv,scan_tv;
    public ListView listView;
    public List<InspectItem> list;
    public JcxAdapter adapter;
    public Intent intent;
    public TextView yh_tv,jczy_tv,jcx_tv,gs_tv,xm_tv,jcType_tv;

    public RelativeLayout error_rl;
    public DbManager dbManager;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_dzg_detail, container, false);
        initView(view);
        dbManager = DBUtil.getInstance(getActivity()).getDBManager();
        return view;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);

        if(isVisibleToUser){


            DzgDetail detail =  ZjApplication.dzgDetail ;


            try{

//                Dic riskDic = dbManager.selector(Dic.class).where("dic_value", "=", detail.RiskType + "").and("dic_type", "=", Constants.RiskType).findFirst();
//                if(riskDic != null){
//                    yh_tv.setText(riskDic.getName());
//                }
                Dic inspectDic = dbManager.selector(Dic.class).where("dic_value", "=", detail.getInspectType() + "").and("dic_type", "=", Constants.InspectType).findFirst();
                if(inspectDic != null){
                    jcType_tv.setText(inspectDic.getName());
                }
            }catch(Exception e){

            }


            String inspectItemName = detail.getInspectItemName();
            if(inspectItemName != null && inspectItemName.equals("null")){
                inspectItemName = "";
            }
            jcx_tv.setText(inspectItemName);


            String orgName = detail.getInspectOrgName();
            if(orgName != null && orgName.equals("null")){
                orgName = "";
            }
            gs_tv.setText(orgName);
            String projectName = detail.getInspectProjectName();
            if(projectName != null && projectName.equals("null")){
                projectName = "";
            }
            xm_tv.setText(projectName);

            String professionName = detail.getInspectProfessionName();
            if(professionName != null && professionName.equals("null")){
                professionName = "";
            }
            jczy_tv.setText(professionName);
        }

    }



    public void initView(View view){
        yh_tv = (TextView) view.findViewById(R.id.yh_value_tv);
        jczy_tv = (TextView) view.findViewById(R.id.jczy_vale_tv);
        jcx_tv = (TextView) view.findViewById(R.id.jcx_value_tv);
        gs_tv = (TextView) view.findViewById(R.id.gs_value_tv);
        xm_tv = (TextView) view.findViewById(R.id.xm_value_tv);
        jcType_tv = (TextView) view.findViewById(R.id.jc_type_value_tv);

    }


}
